package com.guigu.utils;

import com.guigu.pojo.PurchaseOrder;

import java.util.Date;

public class CodeUtils {
    public String getDateCode(){
        Date date = new Date();
        String year = String.valueOf(date.getYear());
        String month = String.valueOf((date.getMonth()+1)<10?"0"+date.getMonth():date.getMonth());
        String day = String.valueOf(date.getDate()<10?"0"+date.getDate():date.getDate());
        String code = year+month+day;
        return code;
    }

    public String getOutboundCode(PurchaseOrder purchaseOrder){
        if(purchaseOrder==null){
            String code = "100"+getDateCode()+"0001";
            return code;
        }
        if(purchaseOrder.getPurchaseOrderNumber()==null){
            String code = "100"+getDateCode()+"0001";
            return code;
        }
        if(getDateCode().substring(getDateCode().length()-4,getDateCode().length()).equals("0101")) {
            String code = "100" + getDateCode() + "0001";
            return code;
        }
        String designId = purchaseOrder.getPurchaseOrderNumber();
        String str = designId.substring(designId.length()-4, designId.length());
        String str2 = (Integer.parseInt(str) + 1) + "";
        String str3 = str2;
        for(int i=0; i<(str.length()-str2.length()); i++){
            str3 = "0"+str3;
        }
        String code = "100" + getDateCode() + str3;
        return code;
    }

}
